package ds.factcom.view.console.payment;

/**
 * 
 * @author Javier De Luca, Maximiliano Herrera, Matias Samblancat
 *
 */

import ds.factcom.controller.payment.PaymentController;
import ds.factcom.exception.ClientHasNotInvoices;
import ds.factcom.exception.ClientHasNotInvoicesPending;
import ds.factcom.exception.EmptyStringException;
import ds.factcom.exception.ExistDomainException;
import ds.factcom.exception.IsNotNumberException;
import ds.factcom.exception.IsNotStringException;
import ds.factcom.exception.NotCorrectDocumentNumberException;
import ds.factcom.exception.NotCorrectDocumentTypeException;
import ds.factcom.exception.NotExistDomainException;
import ds.factcom.view.console.BaseConsoleView;
import ds.factcom.view.validate.ValidatorClient;

public class PaymentConsoleView extends BaseConsoleView {

	private PaymentController paymentController;
	private String stringAux; 
	
	public PaymentConsoleView(PaymentController paymentController){
		this.paymentController = paymentController;
		this.paymentController.addObserver(this);
	}
	
	public void GeneratePayment(){
		System.out.println("-------------------------------------------------------");
		System.out.println("GENERAR PAGO");
		System.out.println("-------------------------------------------------------");
		
		try {
			System.out.print("Indique el tipo de documento "+getMessageDocumentType()+" del cliente:");
			
			stringAux = getScanner().nextLine();
			ValidatorClient.isCorrectDocumentType(stringAux);
			String documentType = stringAux;
			
			System.out.print("Ingrese un Numero de documento: ");
			stringAux = getScanner().nextLine();
			ValidatorClient.isCorrectDocumentNumber(stringAux);
			String documentNumber = stringAux;
			
			paymentController.findClientByDocument(documentType, documentNumber);
			
			System.out.println("El cliente debe: "+paymentController.getMount());
			
			System.out.print("Desea pagar las facturas S/N: ");
			stringAux = getScanner().nextLine();
			if ("S".equalsIgnoreCase(stringAux)){
				paymentController.generatePayment();
			}
		} catch (NumberFormatException e) {
			showErrorMessage(e.getMessage());
		} catch (EmptyStringException e) {
			showErrorMessage(e.getMessage());
		} catch (NotExistDomainException e) {
			showErrorMessage(e.getMessage());
		} catch (ClientHasNotInvoices e) {
			showErrorMessage(e.getMessage());
		} catch (ClientHasNotInvoicesPending e) {
			showErrorMessage(e.getMessage());
		} catch (IsNotNumberException e) {
			showErrorMessage(e.getMessage());
		} catch (ExistDomainException e) {
			showErrorMessage(e.getMessage());
		} catch (IsNotStringException e) {
			showErrorMessage(e.getMessage());
		} catch (NotCorrectDocumentTypeException e) {
			showErrorMessage(e.getMessage());
		} catch (NotCorrectDocumentNumberException e) {
			showErrorMessage(e.getMessage());
		} 
	}
}
